package com.ruoyi.eqmonitor.smdtv.controller;

import java.util.List;

import com.ruoyi.common.core.web.page.PageDomain;
import com.ruoyi.common.core.web.page.TableSupport;
import com.ruoyi.eqmonitor.smdtv.domain.Smdtv8;
import com.ruoyi.eqmonitor.smdtv.service.ISmdtv8Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.utils.poi.ExcelUtil;

import com.ruoyi.common.core.web.page.TableDataInfo;

@Api(tags = "排口")
@RestController
@RequestMapping("/smdtv8")
public class Smdtv8Controller extends BaseController{

    @Autowired
    private ISmdtv8Service smdtv8Service;

    /**
     * 获取排口列表
     */
    @GetMapping("/list")
    public TableDataInfo<?> list(Smdtv8 smdtv8){
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        List<Smdtv8> list = smdtv8Service.selectSmdtv8List(smdtv8,(pageNum - 1) * pageSize,pageSize);
        return getDataTable2(list,smdtv8Service.getTotal(smdtv8));
    }

    /**
     * 获取全部排口
     */
    @GetMapping(value = "/all")
    public AjaxResult all(Smdtv8 smdtv8){
        return AjaxResult.success(smdtv8Service.selectSmdtv8List(smdtv8,null,null));
    }

    /**
     * 根据id查询排口
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return AjaxResult.success(smdtv8Service.selectSmdtv8ById(id));
    }

    /**
     * 新增排口
     */
    @Log(title = "新增排口", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Smdtv8 smdtv8){
        return toAjax(smdtv8Service.save(smdtv8));
    }

    /**
     * 修改排口
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Smdtv8 smdtv8){
        return toAjax(smdtv8Service.updateById(smdtv8));
    }

    /**
     * 传入@PathVariable的格式类似为/1,2,3,4,5时,会自动转为数组
     */
    @Log(title = "删除排口", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(smdtv8Service.removeByIds(Arrays.asList(ids)));
    }

    /**
     * 导出排口
     */
    @Log(title = "导出排口", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Smdtv8 smdtv8){
        List<Smdtv8> list = smdtv8Service.selectSmdtv8List(smdtv8,null,null);
        ExcelUtil<Smdtv8> util = new ExcelUtil<Smdtv8>(Smdtv8.class);
        util.exportExcel(response, list, "排口数据");
    }

    /**
     * 根据水系名称获取排口
     * @param name 水系名
     */
    @ApiOperation("根据水系名称获取排口")
    @GetMapping("/getByName")
    public AjaxResult getByName(String name){
        return AjaxResult.success(smdtv8Service.getByName(name));
    }

}
